<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - src/caffe/util/io.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../index.html">top level</a> - <a href="index.html">src/caffe/util</a> - io.cpp<span style="font-size: 80%;"> (source / <a href="io.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">18</td>
            <td class="headerCovTableEntry">108</td>
            <td class="headerCovTableEntryLo">16.7 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">4</td>
            <td class="headerCovTableEntry">18</td>
            <td class="headerCovTableEntryLo">22.2 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #include &lt;fcntl.h&gt;</a>
<span class="lineNum">       2 </span>            : #include &lt;google/protobuf/io/coded_stream.h&gt;
<span class="lineNum">       3 </span>            : #include &lt;google/protobuf/io/zero_copy_stream_impl.h&gt;
<span class="lineNum">       4 </span>            : #include &lt;google/protobuf/text_format.h&gt;
<span class="lineNum">       5 </span>            : #ifdef USE_OPENCV
<span class="lineNum">       6 </span>            : #include &lt;opencv2/core/core.hpp&gt;
<span class="lineNum">       7 </span>            : #include &lt;opencv2/highgui/highgui.hpp&gt;
<span class="lineNum">       8 </span>            : #include &lt;opencv2/highgui/highgui_c.h&gt;
<span class="lineNum">       9 </span>            : #include &lt;opencv2/imgproc/imgproc.hpp&gt;
<span class="lineNum">      10 </span>            : #endif  // USE_OPENCV
<span class="lineNum">      11 </span>            : #include &lt;stdint.h&gt;
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &lt;algorithm&gt;
<span class="lineNum">      14 </span>            : #include &lt;fstream&gt;  // NOLINT(readability/streams)
<span class="lineNum">      15 </span>            : #include &lt;string&gt;
<span class="lineNum">      16 </span>            : #include &lt;vector&gt;
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : #include &quot;caffe/common.hpp&quot;
<span class="lineNum">      19 </span>            : #include &quot;caffe/proto/caffe.pb.h&quot;
<span class="lineNum">      20 </span>            : #include &quot;caffe/util/io.hpp&quot;
<span class="lineNum">      21 </span>            : 
<span class="lineNum">      22 </span>            : const int kProtoReadBytesLimit = INT_MAX;  // Max size of 2 GB minus 1 byte.
<span class="lineNum">      23 </span>            : 
<span class="lineNum">      24 </span>            : namespace caffe {
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span>            : using google::protobuf::io::FileInputStream;
<span class="lineNum">      27 </span>            : using google::protobuf::io::FileOutputStream;
<span class="lineNum">      28 </span>            : using google::protobuf::io::ZeroCopyInputStream;
<span class="lineNum">      29 </span>            : using google::protobuf::io::CodedInputStream;
<span class="lineNum">      30 </span>            : using google::protobuf::io::ZeroCopyOutputStream;
<span class="lineNum">      31 </span>            : using google::protobuf::io::CodedOutputStream;
<a name="32"><span class="lineNum">      32 </span>            : using google::protobuf::Message;</a>
<span class="lineNum">      33 </span>            : 
<span class="lineNum">      34 </span><span class="lineCov">          1 : bool ReadProtoFromTextFile(const char* filename, Message* proto) {</span>
<span class="lineNum">      35 </span>            :   int fd = open(filename, O_RDONLY);
<span class="lineNum">      36 </span><span class="lineCov">          1 :   CHECK_NE(fd, -1) &lt;&lt; &quot;File not found: &quot; &lt;&lt; filename;</span>
<span class="lineNum">      37 </span><span class="lineCov">          1 :   FileInputStream* input = new FileInputStream(fd);</span>
<span class="lineNum">      38 </span><span class="lineCov">          1 :   bool success = google::protobuf::TextFormat::Parse(input, proto);</span>
<span class="lineNum">      39 </span><span class="lineCov">          1 :   delete input;</span>
<span class="lineNum">      40 </span><span class="lineCov">          1 :   close(fd);</span>
<span class="lineNum">      41 </span><span class="lineCov">          1 :   return success;</span>
<a name="42"><span class="lineNum">      42 </span>            : }</a>
<span class="lineNum">      43 </span>            : 
<span class="lineNum">      44 </span><span class="lineNoCov">          0 : void WriteProtoToTextFile(const Message&amp; proto, const char* filename) {</span>
<span class="lineNum">      45 </span>            :   int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
<span class="lineNum">      46 </span><span class="lineNoCov">          0 :   FileOutputStream* output = new FileOutputStream(fd);</span>
<span class="lineNum">      47 </span><span class="lineNoCov">          0 :   CHECK(google::protobuf::TextFormat::Print(proto, output));</span>
<span class="lineNum">      48 </span><span class="lineNoCov">          0 :   delete output;</span>
<span class="lineNum">      49 </span><span class="lineNoCov">          0 :   close(fd);</span>
<a name="50"><span class="lineNum">      50 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">      51 </span>            : 
<span class="lineNum">      52 </span><span class="lineCov">          1 : bool ReadProtoFromBinaryFile(const char* filename, Message* proto) {</span>
<span class="lineNum">      53 </span>            :   int fd = open(filename, O_RDONLY);
<span class="lineNum">      54 </span><span class="lineCov">          1 :   CHECK_NE(fd, -1) &lt;&lt; &quot;File not found: &quot; &lt;&lt; filename;</span>
<span class="lineNum">      55 </span><span class="lineCov">          1 :   ZeroCopyInputStream* raw_input = new FileInputStream(fd);</span>
<span class="lineNum">      56 </span><span class="lineCov">          1 :   CodedInputStream* coded_input = new CodedInputStream(raw_input);</span>
<span class="lineNum">      57 </span><span class="lineCov">          1 :   coded_input-&gt;SetTotalBytesLimit(kProtoReadBytesLimit, 536870912);</span>
<span class="lineNum">      58 </span>            : 
<span class="lineNum">      59 </span><span class="lineCov">          1 :   bool success = proto-&gt;ParseFromCodedStream(coded_input);</span>
<span class="lineNum">      60 </span>            : 
<span class="lineNum">      61 </span><span class="lineCov">          1 :   delete coded_input;</span>
<span class="lineNum">      62 </span><span class="lineCov">          1 :   delete raw_input;</span>
<span class="lineNum">      63 </span><span class="lineCov">          1 :   close(fd);</span>
<span class="lineNum">      64 </span><span class="lineCov">          1 :   return success;</span>
<a name="65"><span class="lineNum">      65 </span>            : }</a>
<span class="lineNum">      66 </span>            : 
<span class="lineNum">      67 </span><span class="lineNoCov">          0 : void WriteProtoToBinaryFile(const Message&amp; proto, const char* filename) {</span>
<span class="lineNum">      68 </span><span class="lineNoCov">          0 :   fstream output(filename, ios::out | ios::trunc | ios::binary);</span>
<span class="lineNum">      69 </span><span class="lineNoCov">          0 :   CHECK(proto.SerializeToOstream(&amp;output));</span>
<span class="lineNum">      70 </span><span class="lineNoCov">          0 : }</span>
<a name="71"><span class="lineNum">      71 </span>            : </a>
<span class="lineNum">      72 </span>            : #ifdef USE_OPENCV
<span class="lineNum">      73 </span><span class="lineNoCov">          0 : cv::Mat ReadImageToCVMat(const string&amp; filename,</span>
<span class="lineNum">      74 </span>            :     const int height, const int width, const bool is_color) {
<span class="lineNum">      75 </span><span class="lineNoCov">          0 :   cv::Mat cv_img;</span>
<span class="lineNum">      76 </span>            :   int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
<span class="lineNum">      77 </span><span class="lineNoCov">          0 :     CV_LOAD_IMAGE_GRAYSCALE);</span>
<span class="lineNum">      78 </span><span class="lineNoCov">          0 :   cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);</span>
<span class="lineNum">      79 </span><span class="lineNoCov">          0 :   if (!cv_img_origin.data) {</span>
<span class="lineNum">      80 </span><span class="lineNoCov">          0 :     LOG(ERROR) &lt;&lt; &quot;Could not open or find file &quot; &lt;&lt; filename;</span>
<span class="lineNum">      81 </span><span class="lineNoCov">          0 :     return cv_img_origin;</span>
<span class="lineNum">      82 </span>            :   }
<span class="lineNum">      83 </span><span class="lineNoCov">          0 :   if (height &gt; 0 &amp;&amp; width &gt; 0) {</span>
<span class="lineNum">      84 </span><span class="lineNoCov">          0 :     cv::resize(cv_img_origin, cv_img, cv::Size(width, height));</span>
<span class="lineNum">      85 </span>            :   } else {
<span class="lineNum">      86 </span><span class="lineNoCov">          0 :     cv_img = cv_img_origin;</span>
<span class="lineNum">      87 </span>            :   }
<span class="lineNum">      88 </span><span class="lineNoCov">          0 :   return cv_img;</span>
<a name="89"><span class="lineNum">      89 </span>            : }</a>
<span class="lineNum">      90 </span>            : 
<span class="lineNum">      91 </span><span class="lineNoCov">          0 : cv::Mat ReadImageToCVMat(const string&amp; filename,</span>
<span class="lineNum">      92 </span>            :     const int height, const int width) {
<span class="lineNum">      93 </span><span class="lineNoCov">          0 :   return ReadImageToCVMat(filename, height, width, true);</span>
<a name="94"><span class="lineNum">      94 </span>            : }</a>
<span class="lineNum">      95 </span>            : 
<span class="lineNum">      96 </span><span class="lineNoCov">          0 : cv::Mat ReadImageToCVMat(const string&amp; filename,</span>
<span class="lineNum">      97 </span>            :     const bool is_color) {
<span class="lineNum">      98 </span><span class="lineNoCov">          0 :   return ReadImageToCVMat(filename, 0, 0, is_color);</span>
<a name="99"><span class="lineNum">      99 </span>            : }</a>
<span class="lineNum">     100 </span>            : 
<span class="lineNum">     101 </span><span class="lineNoCov">          0 : cv::Mat ReadImageToCVMat(const string&amp; filename) {</span>
<span class="lineNum">     102 </span><span class="lineNoCov">          0 :   return ReadImageToCVMat(filename, 0, 0, true);</span>
<span class="lineNum">     103 </span>            : }
<a name="104"><span class="lineNum">     104 </span>            : </a>
<span class="lineNum">     105 </span>            : // Do the file extension and encoding match?
<span class="lineNum">     106 </span><span class="lineNoCov">          0 : static bool matchExt(const std::string &amp; fn,</span>
<span class="lineNum">     107 </span>            :                      std::string en) {
<span class="lineNum">     108 </span><span class="lineNoCov">          0 :   size_t p = fn.rfind('.');</span>
<span class="lineNum">     109 </span><span class="lineNoCov">          0 :   std::string ext = p != fn.npos ? fn.substr(p+1) : fn;</span>
<span class="lineNum">     110 </span>            :   std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
<span class="lineNum">     111 </span>            :   std::transform(en.begin(), en.end(), en.begin(), ::tolower);
<span class="lineNum">     112 </span><span class="lineNoCov">          0 :   if ( ext == en )</span>
<span class="lineNum">     113 </span>            :     return true;
<span class="lineNum">     114 </span><span class="lineNoCov">          0 :   if ( en == &quot;jpg&quot; &amp;&amp; ext == &quot;jpeg&quot; )</span>
<span class="lineNum">     115 </span>            :     return true;
<span class="lineNum">     116 </span><span class="lineNoCov">          0 :   return false;</span>
<a name="117"><span class="lineNum">     117 </span>            : }</a>
<span class="lineNum">     118 </span>            : 
<span class="lineNum">     119 </span><span class="lineNoCov">          0 : bool ReadImageToDatum(const string&amp; filename, const int label,</span>
<span class="lineNum">     120 </span>            :     const int height, const int width, const bool is_color,
<span class="lineNum">     121 </span>            :     const std::string &amp; encoding, Datum* datum) {
<span class="lineNum">     122 </span><span class="lineNoCov">          0 :   cv::Mat cv_img = ReadImageToCVMat(filename, height, width, is_color);</span>
<span class="lineNum">     123 </span><span class="lineNoCov">          0 :   if (cv_img.data) {</span>
<span class="lineNum">     124 </span><span class="lineNoCov">          0 :     if (encoding.size()) {</span>
<span class="lineNum">     125 </span><span class="lineNoCov">          0 :       if ( (cv_img.channels() == 3) == is_color &amp;&amp; !height &amp;&amp; !width &amp;&amp;</span>
<span class="lineNum">     126 </span><span class="lineNoCov">          0 :           matchExt(filename, encoding) )</span>
<span class="lineNum">     127 </span><span class="lineNoCov">          0 :         return ReadFileToDatum(filename, label, datum);</span>
<span class="lineNum">     128 </span>            :       std::vector&lt;uchar&gt; buf;
<span class="lineNum">     129 </span><span class="lineNoCov">          0 :       cv::imencode(&quot;.&quot;+encoding, cv_img, buf);</span>
<span class="lineNum">     130 </span><span class="lineNoCov">          0 :       datum-&gt;set_data(std::string(reinterpret_cast&lt;char*&gt;(&amp;buf[0]),</span>
<span class="lineNum">     131 </span><span class="lineNoCov">          0 :                       buf.size()));</span>
<span class="lineNum">     132 </span>            :       datum-&gt;set_label(label);
<span class="lineNum">     133 </span>            :       datum-&gt;set_encoded(true);
<span class="lineNum">     134 </span>            :       return true;
<span class="lineNum">     135 </span>            :     }
<span class="lineNum">     136 </span><span class="lineNoCov">          0 :     CVMatToDatum(cv_img, datum);</span>
<span class="lineNum">     137 </span>            :     datum-&gt;set_label(label);
<span class="lineNum">     138 </span><span class="lineNoCov">          0 :     return true;</span>
<span class="lineNum">     139 </span>            :   } else {
<span class="lineNum">     140 </span>            :     return false;
<span class="lineNum">     141 </span>            :   }
<span class="lineNum">     142 </span>            : }
<a name="143"><span class="lineNum">     143 </span>            : #endif  // USE_OPENCV</a>
<span class="lineNum">     144 </span>            : 
<span class="lineNum">     145 </span><span class="lineNoCov">          0 : bool ReadFileToDatum(const string&amp; filename, const int label,</span>
<span class="lineNum">     146 </span>            :     Datum* datum) {
<span class="lineNum">     147 </span>            :   std::streampos size;
<span class="lineNum">     148 </span>            : 
<span class="lineNum">     149 </span><span class="lineNoCov">          0 :   fstream file(filename.c_str(), ios::in|ios::binary|ios::ate);</span>
<span class="lineNum">     150 </span><span class="lineNoCov">          0 :   if (file.is_open()) {</span>
<span class="lineNum">     151 </span><span class="lineNoCov">          0 :     size = file.tellg();</span>
<span class="lineNum">     152 </span><span class="lineNoCov">          0 :     std::string buffer(size, ' ');</span>
<span class="lineNum">     153 </span><span class="lineNoCov">          0 :     file.seekg(0, ios::beg);</span>
<span class="lineNum">     154 </span><span class="lineNoCov">          0 :     file.read(&amp;buffer[0], size);</span>
<span class="lineNum">     155 </span><span class="lineNoCov">          0 :     file.close();</span>
<span class="lineNum">     156 </span><span class="lineNoCov">          0 :     datum-&gt;set_data(buffer);</span>
<span class="lineNum">     157 </span>            :     datum-&gt;set_label(label);
<span class="lineNum">     158 </span>            :     datum-&gt;set_encoded(true);
<span class="lineNum">     159 </span>            :     return true;
<span class="lineNum">     160 </span>            :   } else {
<span class="lineNum">     161 </span>            :     return false;
<span class="lineNum">     162 </span>            :   }
<span class="lineNum">     163 </span>            : }
<a name="164"><span class="lineNum">     164 </span>            : </a>
<span class="lineNum">     165 </span>            : #ifdef USE_OPENCV
<span class="lineNum">     166 </span><span class="lineNoCov">          0 : cv::Mat DecodeDatumToCVMatNative(const Datum&amp; datum) {</span>
<span class="lineNum">     167 </span>            :   cv::Mat cv_img;
<span class="lineNum">     168 </span><span class="lineNoCov">          0 :   CHECK(datum.encoded()) &lt;&lt; &quot;Datum not encoded&quot;;</span>
<span class="lineNum">     169 </span>            :   const string&amp; data = datum.data();
<span class="lineNum">     170 </span><span class="lineNoCov">          0 :   std::vector&lt;char&gt; vec_data(data.c_str(), data.c_str() + data.size());</span>
<span class="lineNum">     171 </span><span class="lineNoCov">          0 :   cv_img = cv::imdecode(vec_data, -1);</span>
<span class="lineNum">     172 </span><span class="lineNoCov">          0 :   if (!cv_img.data) {</span>
<span class="lineNum">     173 </span><span class="lineNoCov">          0 :     LOG(ERROR) &lt;&lt; &quot;Could not decode datum &quot;;</span>
<span class="lineNum">     174 </span>            :   }
<a name="175"><span class="lineNum">     175 </span><span class="lineNoCov">          0 :   return cv_img;</span></a>
<span class="lineNum">     176 </span>            : }
<span class="lineNum">     177 </span><span class="lineNoCov">          0 : cv::Mat DecodeDatumToCVMat(const Datum&amp; datum, bool is_color) {</span>
<span class="lineNum">     178 </span>            :   cv::Mat cv_img;
<span class="lineNum">     179 </span><span class="lineNoCov">          0 :   CHECK(datum.encoded()) &lt;&lt; &quot;Datum not encoded&quot;;</span>
<span class="lineNum">     180 </span>            :   const string&amp; data = datum.data();
<span class="lineNum">     181 </span><span class="lineNoCov">          0 :   std::vector&lt;char&gt; vec_data(data.c_str(), data.c_str() + data.size());</span>
<span class="lineNum">     182 </span>            :   int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
<span class="lineNum">     183 </span><span class="lineNoCov">          0 :     CV_LOAD_IMAGE_GRAYSCALE);</span>
<span class="lineNum">     184 </span><span class="lineNoCov">          0 :   cv_img = cv::imdecode(vec_data, cv_read_flag);</span>
<span class="lineNum">     185 </span><span class="lineNoCov">          0 :   if (!cv_img.data) {</span>
<span class="lineNum">     186 </span><span class="lineNoCov">          0 :     LOG(ERROR) &lt;&lt; &quot;Could not decode datum &quot;;</span>
<span class="lineNum">     187 </span>            :   }
<span class="lineNum">     188 </span><span class="lineNoCov">          0 :   return cv_img;</span>
<span class="lineNum">     189 </span>            : }
<span class="lineNum">     190 </span>            : 
<a name="191"><span class="lineNum">     191 </span>            : // If Datum is encoded will decoded using DecodeDatumToCVMat and CVMatToDatum</a>
<span class="lineNum">     192 </span>            : // If Datum is not encoded will do nothing
<span class="lineNum">     193 </span><span class="lineNoCov">          0 : bool DecodeDatumNative(Datum* datum) {</span>
<span class="lineNum">     194 </span><span class="lineNoCov">          0 :   if (datum-&gt;encoded()) {</span>
<span class="lineNum">     195 </span><span class="lineNoCov">          0 :     cv::Mat cv_img = DecodeDatumToCVMatNative((*datum));</span>
<span class="lineNum">     196 </span><span class="lineNoCov">          0 :     CVMatToDatum(cv_img, datum);</span>
<span class="lineNum">     197 </span>            :     return true;
<span class="lineNum">     198 </span>            :   } else {
<span class="lineNum">     199 </span>            :     return false;
<a name="200"><span class="lineNum">     200 </span>            :   }</a>
<span class="lineNum">     201 </span>            : }
<span class="lineNum">     202 </span><span class="lineNoCov">          0 : bool DecodeDatum(Datum* datum, bool is_color) {</span>
<span class="lineNum">     203 </span><span class="lineNoCov">          0 :   if (datum-&gt;encoded()) {</span>
<span class="lineNum">     204 </span><span class="lineNoCov">          0 :     cv::Mat cv_img = DecodeDatumToCVMat((*datum), is_color);</span>
<span class="lineNum">     205 </span><span class="lineNoCov">          0 :     CVMatToDatum(cv_img, datum);</span>
<span class="lineNum">     206 </span>            :     return true;
<span class="lineNum">     207 </span>            :   } else {
<span class="lineNum">     208 </span>            :     return false;
<span class="lineNum">     209 </span>            :   }
<a name="210"><span class="lineNum">     210 </span>            : }</a>
<span class="lineNum">     211 </span>            : 
<span class="lineNum">     212 </span><span class="lineNoCov">          0 : void CVMatToDatum(const cv::Mat&amp; cv_img, Datum* datum) {</span>
<span class="lineNum">     213 </span><span class="lineNoCov">          0 :   CHECK(cv_img.depth() == CV_8U) &lt;&lt; &quot;Image data type must be unsigned byte&quot;;</span>
<span class="lineNum">     214 </span>            :   datum-&gt;set_channels(cv_img.channels());
<span class="lineNum">     215 </span><span class="lineNoCov">          0 :   datum-&gt;set_height(cv_img.rows);</span>
<span class="lineNum">     216 </span><span class="lineNoCov">          0 :   datum-&gt;set_width(cv_img.cols);</span>
<span class="lineNum">     217 </span>            :   datum-&gt;clear_data();
<span class="lineNum">     218 </span>            :   datum-&gt;clear_float_data();
<span class="lineNum">     219 </span>            :   datum-&gt;set_encoded(false);
<span class="lineNum">     220 </span>            :   int datum_channels = datum-&gt;channels();
<span class="lineNum">     221 </span>            :   int datum_height = datum-&gt;height();
<span class="lineNum">     222 </span>            :   int datum_width = datum-&gt;width();
<span class="lineNum">     223 </span><span class="lineNoCov">          0 :   int datum_size = datum_channels * datum_height * datum_width;</span>
<span class="lineNum">     224 </span><span class="lineNoCov">          0 :   std::string buffer(datum_size, ' ');</span>
<span class="lineNum">     225 </span><span class="lineNoCov">          0 :   for (int h = 0; h &lt; datum_height; ++h) {</span>
<span class="lineNum">     226 </span>            :     const uchar* ptr = cv_img.ptr&lt;uchar&gt;(h);
<span class="lineNum">     227 </span>            :     int img_index = 0;
<span class="lineNum">     228 </span><span class="lineNoCov">          0 :     for (int w = 0; w &lt; datum_width; ++w) {</span>
<span class="lineNum">     229 </span><span class="lineNoCov">          0 :       for (int c = 0; c &lt; datum_channels; ++c) {</span>
<span class="lineNum">     230 </span><span class="lineNoCov">          0 :         int datum_index = (c * datum_height + h) * datum_width + w;</span>
<span class="lineNum">     231 </span><span class="lineNoCov">          0 :         buffer[datum_index] = static_cast&lt;char&gt;(ptr[img_index++]);</span>
<span class="lineNum">     232 </span>            :       }
<span class="lineNum">     233 </span>            :     }
<span class="lineNum">     234 </span>            :   }
<span class="lineNum">     235 </span><span class="lineNoCov">          0 :   datum-&gt;set_data(buffer);</span>
<a name="236"><span class="lineNum">     236 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     237 </span>            : #endif  // USE_OPENCV
<span class="lineNum">     238 </span><span class="lineCov">          3 : }  // namespace caffe</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
